angular.module('routing_basics', [ 'ngRoute'])

.config(function($routeProvider) {

	$routeProvider.when('/admin/users/list', {
		templateUrl : 'templates/list.html',
		controller : 'EditUserCtrl',
		resolve : {
			user : function($route, Users) {
				return Users.get($route.current.params.userid);
			}
		}
	}).when('/admin/users/new', {
		templateUrl : 'templates/new.html',
		controller : 'EditUserCtrl',
		resolve : {
			user : function($route, Users) {
				return Users.get($route.current.params.userid);
			}
		}
	}).when('/edit', {
		templateUrl : 'templates/edit.html',
		controller : 'EditUserCtrl',
		resolve : {
			user : function($route, Users) {
				return Users.get($route.current.params.userid);
			}
		}
	})

	.when('/', {
		templateUrl : 'templates/sellpic.main.html'
	})
	// .otherwise({redirectTo: '/'});
})

.factory('Users', function() {

	var users = [ {
		id : 1,
		name : 'Pawel'
	}, {
		id : 2,
		name : 'Peter'
	} ];

	return {
		query : function() {
			return users;
		},
		add : function(user) {
			return users.push(user);
		},
		get : function(id) {
			return users[id];
		},
		update : function(id, user) {
			users[id] = user;
		}
	};
})

.controller('GalleryCtrl', function($scope, $http) {
	$scope.masonryDataList = [];
	var getItemRes = $http.get('./getGalleryItem.json');
	getItemRes.success(function(data) {
		$scope.galleryDataList = data;
		CommonUI.bind.initMasonry();
	});

})

.controller('SlideCtrl', function($scope, $http) {
	$scope.slideDataList = [];
	var getItemRes = $http.get('./slideData.json');
	getItemRes.success(function(data) {
		$scope.slideDataList = data;
		setTimeout(function() {CommonUI.bind.initSwiper();},10);
	});
})

.controller('NavigationCtrl', function($scope, $location) {
})

.controller('ListUsersCtrl', function($scope, Users) {
	$scope.users = Users.query();
})

.controller('NewUserCtrl', function($scope, Users) {
})

.controller('EditUserCtrl', function($scope, $routeParams, Users, user) {
	$scope.user = user;
});
